import { UtilsBase } from "./UtilsBase";

export abstract class Modifier extends UtilsBase {
    stageValue: any;
    value: any;
    constructor(value: any) {
        super();
        this.stageValue = value;
    }
    modifier(modifiers: any, modifierClass: any, value: any) {
        const identity = modifierClass.identity;
        const item = modifiers.get(identity);
        if (item) {
            item.stageValue = value;
        }
        else {
            modifiers.set(identity, new modifierClass(value));
        }
    }
    applyStage(node: any) {
        if (this.stageValue === this.value) {
            delete this.stageValue;
            return;
        }
        if (typeof this.stageValue === "object" && typeof this.value === "object") {
            if (this.stageValue.isEqual(this.value)) {
                delete this.stageValue;
                return;
            }
        }
        this.value = this.stageValue;
        delete this.stageValue;
        this.applyPeer(node, this.value === undefined);
        return (this.value === undefined);
    }
    applyPeer(node: any, reset: any) { }
}